#pragma once

#include <QVariant>
#include <QMetaType>
#include <vector>
#include<iostream>
#include <QObject>
#include <QThread>
#include<QString>
#include "list_message.h"
#include "QDateTime"
#include <opencv2/opencv.hpp>
using namespace cv;

using namespace std;

#include <atomic>

#include "spdlog/spdlog.h"
#include "spdlog/sinks/daily_file_sink.h"
#include "spdlog/fmt/ostr.h"
extern std::shared_ptr<spdlog::logger> logger ;

#include "save_image.h"

//#include "sldm.h"

#include <QTimer>

#include <com.h>

#include "function.h"
extern COM m_com;

class ShowResult
{
public:
//    cv::Mat m_image;
//    cv::Mat m_image_draw;
    int m_ok_count=0;
    int m_ng_count=0;
    int m_camera_index;
    int m_detection_index;
    bool m_detectin_result;
    QString m_camera_name;
    QString m_messgae;
    double m_time_use ;
	uint m_frame_rate;
    int m_save_right=0;
    int m_save_wrong=0;
    int m_save_roi_right=0;
    int m_save_roi_wrong=0;
    cv::Rect m_roi_rect;
    int m_show_ratio=1;
    HObject m_hobject;
};//<描述一个相机单次检测完后的需要输出到主界面的统计显示信息

//class QtThreadProcess : public QThread
class QtThreadProcess : public QObject
{
    Q_OBJECT
public:
    explicit QtThreadProcess(QObject* parent = nullptr);
   

public:

    int m_delaye_number =0;
    ListMessgae<ShowResult> vector_showresult;

	QTimer*  m_timer_frame_rate = nullptr;
	std::atomic<uint64_t>  m_frame_rate = 0;
	uint64_t  m_image_index_last = 0;

    Function* m_function;
    int m_show_ratio = 1;

    int m_io_camera=0;

    int m_io_result=0;
    int m_io_finish=0;

//    //存图线程
//    SaveImageThread* m_save_image_thread;
//    QString m_save_image_dir;

    QString m_camera_name;

    QString m_image_dir = "";
    vector<QString> m_images_path;

	

    bool  m_proess_state = false ;

    bool m_only_show_state = false  ;




    uint64_t  m_camera_index = 0;//相机的序号


    double m_time_use =0;

    //uint64_t  m_image_index=0;//相机采图图像序号

	std::atomic<uint64_t> m_image_index = 0;//相机采图图像序号

    uint64_t  m_detection_index = 0;//检测序号

   //检测线程中ng和ok的个数
    uint64_t  m_ng_count=0;

    uint64_t  m_ok_count=0;

    uint64_t  m_ng_segmentation_count=0;

    uint64_t m_defect_unknow_count=0;

    ListMessgae<HObject>	m_qDisplayFrameQueue;		///< 待处理显示原始图像队列（输入图像缓冲）

signals:
   void sendDetectionResult(ShowResult result);///<相机对象处理完图像后要发射的信号
   void sendComResult(short data1, short value, short data3);///
   void sendCom(int camera_index,int singal);

//   void sendCameraFinish(short data);
   void sendCameraFinish(short io_camera,short io_finish ,short io_result);
   void sendShowImage(Mat image,int camera_index,int index);///<相机对象处理完图像后要发射的信号
public slots:
   virtual void run();
//    void saveImage(ShowResult result);

};


extern void callback(Mat mat_image,HObject image,void* p);



